package com.centit.suixuan.puremvc.view
{
	import com.centit.suixuan.puremvc.model.MenuProxy;
	import com.centit.suixuan.puremvc.model.User;
	import com.centit.suixuan.puremvc.model.UserProxy;
	
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.controls.Tree;
	import mx.events.DividerEvent;
	
	import org.osmf.containers.MediaContainer;
	import org.osmf.layout.LayoutMetadata;
	import org.osmf.layout.LayoutRendererBase;
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import spark.components.Button;
	import spark.components.Panel;
	
	import mx.events.TreeEvent;
	
	public class MenuMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "MenuMediator";
		public static const MENU_CLICK:String = "MenuClick";
		public static const MENU_OPENING:String = "MenuOpenIng";
		
		
		public function MenuMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			
			this.treeMenu.addEventListener(TreeEvent.ITEM_OPENING, menuOpenIng);
			this.treeMenu.addEventListener(MouseEvent.CLICK, menuClick);
		}
		
		override public function handleNotification(notification:INotification):void
		{
			var obj : Object = notification.getBody();
			
			switch(notification.getName()){
				case MENU_CLICK : new MenuProxy(MenuProxy.NAME, obj).chanPanel();  break;
				case MENU_OPENING : new MenuProxy(MenuProxy.NAME, obj).opening();  break;
				default : break;
			}
		}
		
		override public function listNotificationInterests():Array
		{
			return [
				MENU_CLICK,
				MENU_OPENING,
			];
		}
		
		public function get treeMenu() : Tree {
			return (viewComponent as MainApplication).treeMenu;
		}
		
		private function menuClick(e : MouseEvent) : void {
			super.sendNotification(MENU_CLICK, {treeMenu : e.currentTarget, mainApplication : viewComponent});
		}
		
		private function menuOpenIng(e : TreeEvent) : void {
			super.sendNotification(MENU_OPENING, {e : e, mainApplication : viewComponent});
		}
	}
}